﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text.RegularExpressions;

public partial class Contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder ResponseText = new System.Text.StringBuilder();

        if (Request["Email"].Length > 0 && Request["Subject"].Length > 0 && Request["txMessage"].Length > 0)
        {
            if (Request["Email"].Contains("@") && Request["Email"].Contains("."))
            {

                MailMessage objEmail = new MailMessage();
                //Todo: Set email
                objEmail.To.Add("Your@Email.com");
                objEmail.From = new MailAddress(Request["Email"]);
                objEmail.Subject = "TL Contact:" + Request["Subject"];

                objEmail.Body = Request["txMessage"];
                //smtp Credentials are set in the web.config file
                objEmail.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();

                smtp.Send(objEmail);

                ResponseText.Append("<ul><li>Thank you for your message.  We will get back to you shortly.</li><li><a href='default.aspx' target='self'>Back Home</a></li></ul>");
            }
            else
            {
                ResponseText.Append("<ul><li>Hmm...Somthing was strange about your email address.  Please go back and re-submit.</li></ul>");

            }
        }
        else
        {
            ResponseText.Append("<ul><li>Hmm...You seem to have left one of the form fields blank.  Please go back and re-submit.</li></ul>");
        }
        

        Response.Write(ResponseText.ToString());
        Response.End();


    }
}
